// pages/search/search.js
const db = wx.cloud.database();
const _ = db.command
Page({

    /**
     * 页面的初始数据
     */
    data: {
        key:'',
        toolList:[]
    },
    onChange(key){
        this.setData({
            key:key.detail
        });
        
    },
    search(){
        var {key} = this.data;
        var that = this;
        db.collection('tool').where(_.or([
            {
                detail:db.RegExp({
                    regexp:'^.*'+key,
                })
            },
            {
                name:db.RegExp({
                    regexp:'^.*'+key,
                })
            },
            {
                price:db.RegExp({
                    regexp:'^.*'+key,
                })
            },
            {
                type:db.RegExp({
                    regexp:'^.*'+key,
                })
            },
            {
                'location.name':db.RegExp({
                    regexp:'^.*'+key,
                })    
            },
        ])
        ).get().then(res=>{
            that.setData({
                toolList:res.data
            })
        })
    },
    onPullDownRefresh:function () {
        setTimeout(()=>{ wx.stopPullDownRefresh({
        success: (res) => {}})},1000)  
    }

})